package com.hoyin.viewtest;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.widget.EditText;

import com.hoyin.viewtest.dependencies.layout.RoundProgressBar;

public class RoundProgressBarActivity extends AppCompatActivity {
	private final String TAG = "VerticalProgressBarActivity";
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_round_progress_bar);
		RoundProgressBar progressBar = (RoundProgressBar) findViewById(R.id.progressBar);
		progressBar.setMax(100);
		progressBar.setRoundWidth((float) 30);
		progressBar.setTextColor(Color.DKGRAY);
		progressBar.setTextIsDisplayable(false);
		progressBar.setTextSize(50);
		progressBar.setRotation(-90);
		EditText editText = (EditText) findViewById(R.id.editTextNumber);
		Log.d(TAG, "onCreate()");
		editText.setOnClickListener(view -> {
			runOnUiThread(new Runnable() {
				@Override
				public void run() {
					editText.setText("12333");
				}
			});
		});
		editText.addTextChangedListener(new TextWatcher() {
			@Override
			public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

			}

			@Override
			public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
				runOnUiThread(new Runnable() {
					@Override
					public void run() {
						if (String.valueOf(editText.getText()).equals("")) {
							progressBar.setProgress(0);
							return;
						}
						progressBar.setProgress(Integer.parseInt(String.valueOf(editText.getText())));
						Log.d(TAG, "onTextChanged()" + "  " + Float.parseFloat(String.valueOf(editText.getText()))/100);
					}
				});
			}

			@Override
			public void afterTextChanged(Editable editable) {

			}
		});
	}
}